package dc.exam;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class Main {

	public static void test1() {
		long total = 0;
		long currentCount = 0;
		for (int i = 1; i <= 50; i++) {
			if (i == 1) {
				currentCount = 1;
				total = 1;
			} else {
				currentCount = (long) Math.ceil(2.0 * total / 3.0);
				total += currentCount;
			}
			System.out.println(i + ":" + currentCount + "\t" + total);
		}
	}

	public static TableInfo test2(double discount) {
		List<String> header = new ArrayList<String>();
		List<List<String>> info = new ArrayList<List<String>>();
		header.add("期数");
		header.add("本期注数");
		header.add("本期消费");
		header.add("本期概率");
		header.add("累计注数");
		header.add("累计消费");
		header.add("累计概率");
		header.add("中奖金额");
		header.add("净利润");
		header.add("利润率");
		
		long total = 0;
		long currentCount = 0;
		for (int i = 1; i <= 50; i++) {
			if (i == 1) {
				currentCount = 1;
				total = 1;
			} else {
				currentCount = (long) Math.ceil(2.0 * total * (1 + discount)
						/ (3.0 - 2.0 * discount));
				total += currentCount;
			}
			List<String> c = new ArrayList<String>();
			c.add(""+i);
			c.add(""+currentCount);
			c.add(""+currentCount*2);
			c.add(""+scale(currentRate(1.0/16.0, i),4));
			c.add(""+total);
			c.add(""+total*2);
			c.add(""+scale(aheadRate(1.0/16.0, i),4));
			c.add(""+currentCount*5);
			c.add(""+(currentCount*5-total*2));
			c.add(""+scale((currentCount*5.0-total*2.0)/(total*2.0),3));
			info.add(c);
		}
		
		return new TableInfo(header, info);
	}
	
	public static TableInfo test3(double discount) {
		List<String> header = new ArrayList<String>();
		List<List<String>> info = new ArrayList<List<String>>();
		header.add("期数");
		header.add("本期注数");
		header.add("本期消费");
		header.add("本期概率");
		header.add("累计注数");
		header.add("累计消费");
		header.add("累计概率");
		header.add("中奖金额");
		header.add("净利润");
		header.add("利润率");
		
		long total = 0;
		long currentCount = 0;
		for (int i = 1; i <= 50; i++) {
			if (i == 1) {
				currentCount = 1;
				total = 1;
			} else {
				currentCount = (long) Math.ceil(2.0 * total * (1 + discount)
						/ (3.0 - 2.0 * discount));
				total += currentCount;
			}
			List<String> c = new ArrayList<String>();
			c.add(""+i);
			c.add(""+currentCount);
			c.add(""+currentCount*2);
			c.add(""+scale(currentRate(1.0/16.0, i),4));
			c.add(""+total);
			c.add(""+total*2);
			c.add(""+scale(aheadRate(1.0/16.0, i),4));
			c.add(""+currentCount*5);
			c.add(""+(currentCount*5-total*2));
			c.add(""+scale((currentCount*5.0-total*2.0)/(total*2.0),3));
			info.add(c);
		}
		
		return new TableInfo(header, info);
	}

	public static Double scale(Double number,int bits){
		BigDecimal b = new BigDecimal(number);
        return b.setScale(bits, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
	
	public static Double aheadRate(double singleRate,int count){
		return 1.0 - Math.pow((1.0-singleRate), count);
	}

	public static Double currentRate(double singleRate,int count){
		return singleRate * Math.pow((1.0-singleRate), count-1);
	}
	

	public static void main(String[] args) {
		
//		String path = "C:\\Users\\Administrator\\Desktop\\双色球\\blue\\";
//
//		for(int i = 0; i<= 50; i++){
//			double discount = i / 100.0;
//			TableInfo ti = test2(discount);
//			String dp = path+i+".htm";
//			FileUtils.writeFile(dp, ti.toString(), "gbk");
//		}
		UUID.randomUUID();
		
	}

}
